#coding=utf-8
#Boa:FramePanel:PanelMallCheck

import wx

from MyListCtrl import MySimpleListCtrl

from product import CDataMallProfit,CDataExpense
import kit


[wxID_PANELMALLCHECK, wxID_PANELMALLCHECKBTNDEL, wxID_PANELMALLCHECKBTNMODIFY, 
 wxID_PANELMALLCHECKBTNRECALC, wxID_PANELMALLCHECKBTNSAVE, 
 wxID_PANELMALLCHECKDATEEND, wxID_PANELMALLCHECKDATESTART, 
 wxID_PANELMALLCHECKSTATICTEXT1, wxID_PANELMALLCHECKSTATICTEXT10, 
 wxID_PANELMALLCHECKSTATICTEXT11, wxID_PANELMALLCHECKSTATICTEXT12, 
 wxID_PANELMALLCHECKSTATICTEXT13, wxID_PANELMALLCHECKSTATICTEXT14, 
 wxID_PANELMALLCHECKSTATICTEXT15, wxID_PANELMALLCHECKSTATICTEXT16, 
 wxID_PANELMALLCHECKSTATICTEXT17, wxID_PANELMALLCHECKSTATICTEXT18, 
 wxID_PANELMALLCHECKSTATICTEXT19, wxID_PANELMALLCHECKSTATICTEXT2, 
 wxID_PANELMALLCHECKSTATICTEXT20, wxID_PANELMALLCHECKSTATICTEXT22, 
 wxID_PANELMALLCHECKSTATICTEXT3, wxID_PANELMALLCHECKSTATICTEXT4, 
 wxID_PANELMALLCHECKSTATICTEXT5, wxID_PANELMALLCHECKSTATICTEXT6, 
 wxID_PANELMALLCHECKSTATICTEXT7, wxID_PANELMALLCHECKSTATICTEXT8, 
 wxID_PANELMALLCHECKSTATICTEXT9, wxID_PANELMALLCHECKSTPERCENTCOSTTONG, 
 wxID_PANELMALLCHECKSTPERCENTCOSTYI, wxID_PANELMALLCHECKSTPERCENTFEETONG, 
 wxID_PANELMALLCHECKSTPERCENTFEEYI, wxID_PANELMALLCHECKSTPERCENTFILLTONG, 
 wxID_PANELMALLCHECKSTPERCENTFILLYI, wxID_PANELMALLCHECKSTPERCENTNETPROFIT, 
 wxID_PANELMALLCHECKSTPERCENTNETPROFITTONG, 
 wxID_PANELMALLCHECKSTPERCENTNETPROFITYI, wxID_PANELMALLCHECKTCDISCOUNTYI, 
 wxID_PANELMALLCHECKTCEXPENSE, wxID_PANELMALLCHECKTCEXPENSEPERCENT, 
 wxID_PANELMALLCHECKTCFILLBACKTONG, wxID_PANELMALLCHECKTCFILLBACKYI, 
 wxID_PANELMALLCHECKTCKICKBACKTONG, wxID_PANELMALLCHECKTCKICKBACKYI, 
 wxID_PANELMALLCHECKTCMALLEXPENSE, wxID_PANELMALLCHECKTCMEMO, 
 wxID_PANELMALLCHECKTCNETPROFIT, wxID_PANELMALLCHECKTCNETPROFITTONG, 
 wxID_PANELMALLCHECKTCNETPROFITYI, wxID_PANELMALLCHECKTCPURCHASETONG, 
 wxID_PANELMALLCHECKTCPURCHASEYI, wxID_PANELMALLCHECKTCSALESTONG, 
 wxID_PANELMALLCHECKTCSALESYI, wxID_PANELMALLCHECKTCTONGTOTAL, 
 wxID_PANELMALLCHECKTCYIAMOUNT, wxID_PANELMALLCHECKTCYITOTAL, 
] = [wx.NewId() for _init_ctrls in range(56)]

class PanelMallCheck(wx.Panel):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Panel.__init__(self, id=wxID_PANELMALLCHECK, name=u'PanelMallCheck',
              parent=prnt, pos=wx.Point(744, 217), size=wx.Size(1016, 729),
              style=wx.TAB_TRAVERSAL)
        self.SetClientSize(wx.Size(1000, 691))
        self.SetClientSize(wx.Size(1000, 691))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'\u6977\u4f53_GB2312'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))

        self.staticText2 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT2,
              label=u'\u8d77\u6b62\u65e5\u671f', name='staticText2',
              parent=self, pos=wx.Point(48, 64), size=wx.Size(68, 16), style=0)

        self.dateStart = wx.DatePickerCtrl(id=wxID_PANELMALLCHECKDATESTART,
              name=u'dateStart', parent=self, pos=wx.Point(136, 56),
              size=wx.Size(121, 24), style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
        self.dateStart.Bind(wx.EVT_DATE_CHANGED, self.OnDateStartDateChanged,
              id=wxID_PANELMALLCHECKDATESTART)

        self.staticText3 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT3,
              label=u'\u81f3', name='staticText3', parent=self,
              pos=wx.Point(264, 64), size=wx.Size(17, 16), style=0)

        self.dateEnd = wx.DatePickerCtrl(id=wxID_PANELMALLCHECKDATEEND,
              name=u'dateEnd', parent=self, pos=wx.Point(296, 56),
              size=wx.Size(121, 24), style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
        self.dateEnd.Bind(wx.EVT_DATE_CHANGED, self.OnDateEndDateChanged,
              id=wxID_PANELMALLCHECKDATEEND)

        self.btnRecalc = wx.Button(id=wxID_PANELMALLCHECKBTNRECALC,
              label=u'\u8ba1\u7b97', name=u'btnRecalc', parent=self,
              pos=wx.Point(424, 56), size=wx.Size(93, 26), style=0)
        self.btnRecalc.Bind(wx.EVT_BUTTON, self.OnBtnRecalcButton,
              id=wxID_PANELMALLCHECKBTNRECALC)

        self.staticText1 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT1,
              label=u'\u4e00\u3001\u6613\u5929\u8fbe\u9500\u552e\u6bdb\u5229\u6da6',
              name='staticText1', parent=self, pos=wx.Point(48, 112),
              size=wx.Size(170, 16), style=0)

        self.staticText4 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT4,
              label=u'\u5546\u54c1\u9500\u552e\u91d1\u989d', name='staticText4',
              parent=self, pos=wx.Point(112, 336), size=wx.Size(102, 16),
              style=0)

        self.staticText5 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT5,
              label=u'\u51cf\uff1a\u91c7\u8d2d\u6210\u672c', name='staticText5',
              parent=self, pos=wx.Point(112, 368), size=wx.Size(102, 16),
              style=0)

        self.staticText7 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT7,
              label=u'\u51cf\uff1a\u5e73\u53f0\u62bd\u4f63', name='staticText7',
              parent=self, pos=wx.Point(112, 400), size=wx.Size(102, 16),
              style=0)

        self.staticText8 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT8,
              label=u'\u4e09\u3001\u8fd0\u8425\u5f00\u652f', name='staticText8',
              parent=self, pos=wx.Point(72, 464), size=wx.Size(102, 16),
              style=0)

        self.staticText9 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT9,
              label=u'\u4e8c\u3001\u540c\u83b1\u521b\u9500\u552e\u6bdb\u5229\u6da6',
              name='staticText9', parent=self, pos=wx.Point(56, 304),
              size=wx.Size(170, 16), style=0)

        self.staticText12 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT12,
              label=u'\u5546\u54c1\u9500\u552e\u91d1\u989d',
              name='staticText12', parent=self, pos=wx.Point(112, 144),
              size=wx.Size(102, 16), style=0)

        self.staticText13 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT13,
              label=u'\u51cf\uff1a\u91c7\u8d2d\u6210\u672c',
              name='staticText13', parent=self, pos=wx.Point(112, 176),
              size=wx.Size(102, 16), style=0)

        self.staticText10 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT10,
              label=u'\u51cf\uff1a\u8ba2\u5355\u6298\u6263',
              name='staticText10', parent=self, pos=wx.Point(112, 208),
              size=wx.Size(102, 16), style=0)

        self.staticText11 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT11,
              label=u'\u51cf\uff1a\u5e73\u53f0\u62bd\u4f63',
              name='staticText11', parent=self, pos=wx.Point(112, 240),
              size=wx.Size(102, 16), style=0)

        self.staticText15 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT15,
              label=u'\u51cf\uff1a\u5e73\u53f0\u56de\u586b',
              name='staticText15', parent=self, pos=wx.Point(112, 432),
              size=wx.Size(102, 16), style=0)

        self.staticText16 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT16,
              label=u'\u51cf\uff1a\u5e73\u53f0\u56de\u586b',
              name='staticText16', parent=self, pos=wx.Point(112, 272),
              size=wx.Size(102, 16), style=0)

        self.staticText17 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT17,
              label=u'\u56db\u3001\u51c0\u5229\u6da6\u5408\u8ba1',
              name='staticText17', parent=self, pos=wx.Point(72, 528),
              size=wx.Size(119, 16), style=0)

        self.tcPurchaseYi = wx.TextCtrl(id=wxID_PANELMALLCHECKTCPURCHASEYI,
              name=u'tcPurchaseYi', parent=self, pos=wx.Point(240, 168),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcPurchaseYi.Bind(wx.EVT_TEXT, self.OnTcPurchaseYiText,
              id=wxID_PANELMALLCHECKTCPURCHASEYI)

        self.tcNetProfitYi = wx.TextCtrl(id=wxID_PANELMALLCHECKTCNETPROFITYI,
              name=u'tcNetProfitYi', parent=self, pos=wx.Point(240, 104),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcNetProfitYi.Bind(wx.EVT_TEXT, self.OnTcNetProfitYiText,
              id=wxID_PANELMALLCHECKTCNETPROFITYI)

        self.tcDiscountYi = wx.TextCtrl(id=wxID_PANELMALLCHECKTCDISCOUNTYI,
              name=u'tcDiscountYi', parent=self, pos=wx.Point(240, 200),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcDiscountYi.Bind(wx.EVT_TEXT, self.OnTcDiscountYiText,
              id=wxID_PANELMALLCHECKTCDISCOUNTYI)

        self.tcKickbackYi = wx.TextCtrl(id=wxID_PANELMALLCHECKTCKICKBACKYI,
              name=u'tcKickbackYi', parent=self, pos=wx.Point(240, 232),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcKickbackYi.SetBackgroundColour(wx.Colour(128, 255, 128))
        self.tcKickbackYi.Bind(wx.EVT_TEXT, self.OnTcKickbackYiText,
              id=wxID_PANELMALLCHECKTCKICKBACKYI)

        self.tcFillBackYi = wx.TextCtrl(id=wxID_PANELMALLCHECKTCFILLBACKYI,
              name=u'tcFillBackYi', parent=self, pos=wx.Point(240, 264),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcFillBackYi.SetBackgroundColour(wx.Colour(128, 255, 128))
        self.tcFillBackYi.Bind(wx.EVT_TEXT, self.OnTcFillBackYiText,
              id=wxID_PANELMALLCHECKTCFILLBACKYI)

        self.tcNetProfitTong = wx.TextCtrl(id=wxID_PANELMALLCHECKTCNETPROFITTONG,
              name=u'tcNetProfitTong', parent=self, pos=wx.Point(240, 296),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcNetProfitTong.Bind(wx.EVT_TEXT, self.OnTcNetProfitTongText,
              id=wxID_PANELMALLCHECKTCNETPROFITTONG)

        self.tcSalesTong = wx.TextCtrl(id=wxID_PANELMALLCHECKTCSALESTONG,
              name=u'tcSalesTong', parent=self, pos=wx.Point(240, 328),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcSalesTong.Bind(wx.EVT_TEXT, self.OnTcSalesTongText,
              id=wxID_PANELMALLCHECKTCSALESTONG)

        self.tcPurchaseTong = wx.TextCtrl(id=wxID_PANELMALLCHECKTCPURCHASETONG,
              name=u'tcPurchaseTong', parent=self, pos=wx.Point(240, 360),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcPurchaseTong.Bind(wx.EVT_TEXT, self.OnTcPurchaseTongText,
              id=wxID_PANELMALLCHECKTCPURCHASETONG)

        self.tcKickbackTong = wx.TextCtrl(id=wxID_PANELMALLCHECKTCKICKBACKTONG,
              name=u'tcKickbackTong', parent=self, pos=wx.Point(240, 392),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcKickbackTong.SetBackgroundColour(wx.Colour(128, 255, 128))
        self.tcKickbackTong.Bind(wx.EVT_TEXT, self.OnTcKickbackTongText,
              id=wxID_PANELMALLCHECKTCKICKBACKTONG)

        self.tcExpense = wx.TextCtrl(id=wxID_PANELMALLCHECKTCEXPENSE,
              name=u'tcExpense', parent=self, pos=wx.Point(240, 456),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcExpense.Bind(wx.EVT_TEXT, self.OnTcExpenseText,
              id=wxID_PANELMALLCHECKTCEXPENSE)

        self.tcFillBackTong = wx.TextCtrl(id=wxID_PANELMALLCHECKTCFILLBACKTONG,
              name=u'tcFillBackTong', parent=self, pos=wx.Point(240, 424),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcFillBackTong.SetBackgroundColour(wx.Colour(128, 255, 128))
        self.tcFillBackTong.Bind(wx.EVT_TEXT, self.OnTcFillBackTongText,
              id=wxID_PANELMALLCHECKTCFILLBACKTONG)

        self.tcMemo = wx.TextCtrl(id=wxID_PANELMALLCHECKTCMEMO, name=u'tcMemo',
              parent=self, pos=wx.Point(520, 464), size=wx.Size(416, 120),
              style=wx.TE_MULTILINE, value=u'')

        self.tcSalesYi = wx.TextCtrl(id=wxID_PANELMALLCHECKTCSALESYI,
              name=u'tcSalesYi', parent=self, pos=wx.Point(240, 136),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcSalesYi.Bind(wx.EVT_TEXT, self.OnTcSalesYiText,
              id=wxID_PANELMALLCHECKTCSALESYI)

        self.tcNetProfit = wx.TextCtrl(id=wxID_PANELMALLCHECKTCNETPROFIT,
              name=u'tcNetProfit', parent=self, pos=wx.Point(240, 520),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcNetProfit.Bind(wx.EVT_TEXT, self.OnTcNetProfitText,
              id=wxID_PANELMALLCHECKTCNETPROFIT)

        self.btnDel = wx.Button(id=wxID_PANELMALLCHECKBTNDEL,
              label=u'\u5220\u9664', name=u'btnDel', parent=self,
              pos=wx.Point(864, 56), size=wx.Size(93, 26), style=0)
        self.btnDel.Bind(wx.EVT_BUTTON, self.OnBtnDelButton,
              id=wxID_PANELMALLCHECKBTNDEL)

        self.btnModify = wx.Button(id=wxID_PANELMALLCHECKBTNMODIFY,
              label=u'\u4fdd\u5b58\u4fee\u6539', name=u'btnModify', parent=self,
              pos=wx.Point(864, 24), size=wx.Size(93, 26), style=0)
        self.btnModify.Bind(wx.EVT_BUTTON, self.OnBtnModifyButton,
              id=wxID_PANELMALLCHECKBTNMODIFY)

        self.btnSave = wx.Button(id=wxID_PANELMALLCHECKBTNSAVE,
              label=u'\u4fdd\u5b58\u65b0\u8868', name=u'btnSave', parent=self,
              pos=wx.Point(760, 56), size=wx.Size(93, 26), style=0)
        self.btnSave.Bind(wx.EVT_BUTTON, self.OnBtnSaveButton,
              id=wxID_PANELMALLCHECKBTNSAVE)

        self.stPercentNetProfitYi = wx.StaticText(id=wxID_PANELMALLCHECKSTPERCENTNETPROFITYI,
              label=u'=%', name=u'stPercentNetProfitYi', parent=self,
              pos=wx.Point(384, 112), size=wx.Size(18, 16), style=0)

        self.stPercentNetProfitTong = wx.StaticText(id=wxID_PANELMALLCHECKSTPERCENTNETPROFITTONG,
              label=u'=%', name=u'stPercentNetProfitTong', parent=self,
              pos=wx.Point(384, 304), size=wx.Size(18, 16), style=0)

        self.stPercentNetProfit = wx.StaticText(id=wxID_PANELMALLCHECKSTPERCENTNETPROFIT,
              label=u'=%', name=u'stPercentNetProfit', parent=self,
              pos=wx.Point(384, 528), size=wx.Size(18, 16), style=0)

        self.staticText14 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT14,
              label=u'%\uff0c\u9500/5w', name='staticText14', parent=self,
              pos=wx.Point(432, 464), size=wx.Size(70, 16), style=0)

        self.staticText20 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT20,
              label=u'\u5546\u57ce\u5229\u6da6\u5206\u6790',
              name='staticText20', parent=self, pos=wx.Point(184, 24),
              size=wx.Size(102, 16), style=0)

        self.tcExpensePercent = wx.TextCtrl(id=wxID_PANELMALLCHECKTCEXPENSEPERCENT,
              name=u'tcExpensePercent', parent=self, pos=wx.Point(384, 456),
              size=wx.Size(40, 26), style=wx.TE_RIGHT, value=u'')

        self.staticText22 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT22,
              label=u'\u56db\u3001\u8d39\u7528\u5f00\u652f\uff1a\u5546\u57ce',
              name='staticText22', parent=self, pos=wx.Point(72, 496),
              size=wx.Size(153, 16), style=0)

        self.tcMallExpense = wx.TextCtrl(id=wxID_PANELMALLCHECKTCMALLEXPENSE,
              name=u'tcMallExpense', parent=self, pos=wx.Point(240, 488),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcMallExpense.Bind(wx.EVT_TEXT, self.OnTcMallExpenseText,
              id=wxID_PANELMALLCHECKTCMALLEXPENSE)

        self.stPercentCostYi = wx.StaticText(id=wxID_PANELMALLCHECKSTPERCENTCOSTYI,
              label=u'%', name=u'stPercentCostYi', parent=self,
              pos=wx.Point(384, 176), size=wx.Size(9, 16), style=0)

        self.stPercentFeeYi = wx.StaticText(id=wxID_PANELMALLCHECKSTPERCENTFEEYI,
              label=u'%', name=u'stPercentFeeYi', parent=self, pos=wx.Point(384,
              240), size=wx.Size(9, 16), style=0)

        self.stPercentFillYi = wx.StaticText(id=wxID_PANELMALLCHECKSTPERCENTFILLYI,
              label=u'%', name=u'stPercentFillYi', parent=self,
              pos=wx.Point(384, 272), size=wx.Size(9, 16), style=0)

        self.stPercentCostTong = wx.StaticText(id=wxID_PANELMALLCHECKSTPERCENTCOSTTONG,
              label=u'%', name=u'stPercentCostTong', parent=self,
              pos=wx.Point(384, 368), size=wx.Size(9, 16), style=0)

        self.stPercentFeeTong = wx.StaticText(id=wxID_PANELMALLCHECKSTPERCENTFEETONG,
              label=u'%', name=u'stPercentFeeTong', parent=self,
              pos=wx.Point(384, 400), size=wx.Size(9, 16), style=0)

        self.stPercentFillTong = wx.StaticText(id=wxID_PANELMALLCHECKSTPERCENTFILLTONG,
              label=u'%', name=u'stPercentFillTong', parent=self,
              pos=wx.Point(384, 432), size=wx.Size(9, 16), style=0)

        self.staticText18 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT18,
              label=u'\u8ba2\u5355\u603b\u989d(+\u8865\u5dee)\uff1a',
              name='staticText18', parent=self, pos=wx.Point(432, 144),
              size=wx.Size(146, 16), style=0)

        self.staticText6 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT6,
              label=u'\u6613\u5929\u8fbe\u5e73\u53f0\u603b\u989d\uff1a',
              name='staticText6', parent=self, pos=wx.Point(432, 208),
              size=wx.Size(136, 16), style=0)

        self.tcYiTotal = wx.TextCtrl(id=wxID_PANELMALLCHECKTCYITOTAL,
              name=u'tcYiTotal', parent=self, pos=wx.Point(432, 232),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcYiTotal.SetBackgroundColour(wx.Colour(128, 255, 128))

        self.staticText19 = wx.StaticText(id=wxID_PANELMALLCHECKSTATICTEXT19,
              label=u'\u540c\u83b1\u521b\u5e73\u53f0\u603b\u989d\uff1a',
              name='staticText19', parent=self, pos=wx.Point(432, 304),
              size=wx.Size(136, 16), style=0)

        self.tcTongTotal = wx.TextCtrl(id=wxID_PANELMALLCHECKTCTONGTOTAL,
              name=u'tcTongTotal', parent=self, pos=wx.Point(432, 328),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')
        self.tcTongTotal.SetBackgroundColour(wx.Colour(128, 255, 128))

        self.tcYiAmount = wx.TextCtrl(id=wxID_PANELMALLCHECKTCYIAMOUNT,
              name=u'tcYiAmount', parent=self, pos=wx.Point(432, 168),
              size=wx.Size(136, 26), style=wx.TE_RIGHT, value=u'')

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        self.curObj = None

        self.dateStart.SetValue(wx.DateTime.Today())
        self.dateEnd.SetValue(wx.DateTime.Today())

        cols = [(CDataMallProfit.fi_id, wx.LIST_FORMAT_LEFT, 110),
                (CDataMallProfit.fi_SalesTotal, wx.LIST_FORMAT_RIGHT, 120),
                (CDataMallProfit.fi_NetProfit, wx.LIST_FORMAT_RIGHT, 120)]
                
        #self.listCtrl  = MyListCtrlDecorator(self.lc, cols, CDataCustomerRegion)
        
        self.lc = MySimpleListCtrl(self, CDataMallProfit, cols)
        self.lc.Move(wx.Point(610, 96))
        self.lc.SetSize(wx.Size(360, 350))
        #self.lc.refresh()
        self.lc.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnListItemSelected)

        self.btnModify.Enable(False)
        self.btnDel.Enable(False)
        
    def OnListItemSelected(self, event):
        item = self.lc.GetNextItem(-1, state = wx.LIST_STATE_SELECTED)
        if (item == -1):
            return

        self.curObj = CDataMallProfit.getData({"id":self.lc.GetItemText(item)})
        self.ShowData()

        self.btnModify.Enable(True)
        self.btnDel.Enable(True)

    def ShowData(self):
        obj = self.curObj
        
        date = obj.getValue(obj.fi_dateStart)
        #self.dateStart.SetValue(date)
        self.dateStart.SetValue(wx.DateTimeFromDMY(date.day, date.month-1, date.year,0,0,0))
        date = obj.getValue(obj.fi_dateEnd)
        #self.dateEnd.SetValue(date)
        self.dateEnd.SetValue(wx.DateTimeFromDMY(date.day, date.month-1, date.year,0,0,0))
        #self.stDays.SetLabel("%d" %self.GetDays())

        self.tcNetProfitYi.SetValue("%.0f" %(obj.getValue(obj.fi_GrossProfitYi)))
        self.tcSalesYi.SetValue("%.0f" %(obj.getValue(obj.fi_SalesYi)))
        self.tcPurchaseYi.SetValue("%.0f" %(obj.getValue(obj.fi_PurchaseYi)))
        self.tcDiscountYi.SetValue("%.0f" %(obj.getValue(obj.fi_DiscountYi)))
        self.tcKickbackYi.SetValue("%.0f" %(obj.getValue(obj.fi_KickbackYi)))
        self.tcFillBackYi.SetValue("%.0f" %(obj.getValue(obj.fi_FillbackYi)))

        self.tcNetProfitTong.SetValue("%.0f" %(obj.getValue(obj.fi_GrossProfitTong)))
        self.tcSalesTong.SetValue("%.0f" %(obj.getValue(obj.fi_SalesTong)))
        self.tcPurchaseTong.SetValue("%.0f" %(obj.getValue(obj.fi_PurchaseTong)))
        #self.tcDiscountTong.SetValue("%.0f" %(obj.getValue(obj.fi_DiscountTong)))
        self.tcKickbackTong.SetValue("%.0f" %(obj.getValue(obj.fi_KickbackTong)))
        self.tcFillBackTong.SetValue("%.0f" %(obj.getValue(obj.fi_FillbackTong)))

        self.tcExpense.SetValue("%.0f" %(obj.getValue(obj.fi_Expense)))
        self.tcNetProfit.SetValue("%.0f" %(obj.getValue(obj.fi_NetProfit)))
        self.tcMemo.SetValue(obj.getValue(obj.fi_Memo))

        self.tcMallExpense.SetValue("%.0f" %(obj.getValue(obj.fi_MallExpense)))

        self.tcYiAmount.SetValue("%.0f" %(obj.getValue(obj.fi_SalesTotalYi) or 0))
        self.tcYiTotal.SetValue("%.0f" %(obj.getValue(obj.fi_TotalYi) or 0))
        self.tcTongTotal.SetValue("%.0f" %(obj.getValue(obj.fi_TotalTong) or 0))


    def getData(self):

        data = {
            CDataMallProfit.fi_dateStart : kit.str2Date(self.dateStart.GetValue().Format('%Y-%m-%d')),
            CDataMallProfit.fi_dateEnd : kit.str2Date(self.dateEnd.GetValue().Format('%Y-%m-%d')),
            CDataMallProfit.fi_GrossProfitYi : kit.toFloatOrZero(self.tcNetProfitYi.GetValue()),
            CDataMallProfit.fi_SalesYi : kit.toFloatOrZero(self.tcSalesYi.GetValue()),
            CDataMallProfit.fi_PurchaseYi : kit.toFloatOrZero(self.tcPurchaseYi.GetValue()),
            CDataMallProfit.fi_DiscountYi : kit.toFloatOrZero(self.tcDiscountYi.GetValue()),
            CDataMallProfit.fi_KickbackYi : kit.toFloatOrZero(self.tcKickbackYi.GetValue()),
            CDataMallProfit.fi_FillbackYi : kit.toFloatOrZero(self.tcFillBackYi.GetValue()),
            
            CDataMallProfit.fi_GrossProfitTong : kit.toFloatOrZero(self.tcNetProfitTong.GetValue()),
            CDataMallProfit.fi_SalesTong : kit.toFloatOrZero(self.tcSalesTong.GetValue()),
            CDataMallProfit.fi_PurchaseTong : kit.toFloatOrZero(self.tcPurchaseTong.GetValue()),
            CDataMallProfit.fi_DiscountTong : 0,#kit.toFloatOrZero(self.tcDiscountTong.GetValue()),
            CDataMallProfit.fi_KickbackTong : kit.toFloatOrZero(self.tcKickbackTong.GetValue()),
            CDataMallProfit.fi_FillbackTong : kit.toFloatOrZero(self.tcFillBackTong.GetValue()),

            CDataMallProfit.fi_Expense : kit.toFloatOrZero(self.tcExpense.GetValue()),
            CDataMallProfit.fi_MallExpense : kit.toFloatOrZero(self.tcMallExpense.GetValue()),

            CDataMallProfit.fi_NetProfit : kit.toFloatOrZero(self.tcNetProfit.GetValue()),
            CDataMallProfit.fi_Memo : self.tcMemo.GetValue(),

            CDataMallProfit.fi_SalesTotal : kit.toFloatOrZero(self.tcSalesYi.GetValue())+ kit.toFloatOrZero(self.tcSalesTong.GetValue()),

            CDataMallProfit.fi_SalesTotalYi : kit.toFloatOrZero(self.tcYiAmount.GetValue()),
            CDataMallProfit.fi_TotalYi : kit.toFloatOrZero(self.tcYiTotal.GetValue()),
            CDataMallProfit.fi_TotalTong : kit.toFloatOrZero(self.tcTongTotal.GetValue()),
        }

        return data

    def OnDateStartDateChanged(self, event):
        event.Skip()

    def OnDateEndDateChanged(self, event):
        event.Skip()

    def OnBtnRecalcButton(self, event):

        dateStart = self.dateStart.GetValue().Format('%Y-%m-%d')
        dateEnd = self.dateEnd.GetValue().Format('%Y-%m-%d')

        sales,cost = CDataMallProfit.GetSales(dateStart, dateEnd, CDataMallProfit.ROUTE_YI)
        #print (sales,cost)
        total,discount = CDataMallProfit.GetDiscount(dateStart, dateEnd, CDataMallProfit.ROUTE_YI)
        #self.tcNetProfitYi.SetValue(CDataMallProfit.Get)
        self.tcSalesYi.SetValue('%.0f' %(sales or 0))
        self.tcPurchaseYi.SetValue('%.0f' %(cost or 0))
        self.tcDiscountYi.SetValue('%.0f' %(discount or 0))
        self.tcKickbackYi.SetValue('%.0f' %( (sales or 0) * CDataMallProfit.Yi_Kickback or 0))
        #self.tcFillBackYi.SetValue("%.0f" %(obj.getValue(obj.fi_FillbackYi)))

        self.tcYiAmount.SetValue('%.0f' %(total or 0))

        sales,cost = CDataMallProfit.GetSales(dateStart, dateEnd, CDataMallProfit.ROUTE_TONG)
        total,discount = CDataMallProfit.GetDiscount(dateStart, dateEnd, CDataMallProfit.ROUTE_TONG)
        #self.tcNetProfitTong.SetValue(CDataMallProfit.Get)
        self.tcSalesTong.SetValue('%.0f' %(sales-discount or 0))
        self.tcPurchaseTong.SetValue('%.0f' %(cost or 0))
        #self.tcDiscountTong.SetValue('%.0f' %(discount or 0))
        self.tcKickbackTong.SetValue('%.0f' %( (sales or 0) * CDataMallProfit.Tong_Kickback or 0))
        #self.tcFillBackTong.SetValue("%.0f" %(obj.getValue(obj.fi_FillbackYi)))

        #self.tcExpense.SetValue()
        #self.tcNetProfit.SetValue("%.0f" %(obj.getValue(obj.fi_NetProfit)))

        mallExpense = CDataExpense.GetMallExpense(dateStart, dateEnd)
        self.tcMallExpense.SetValue('%.0f' %(mallExpense or 0))

        

    def OnBtnSaveButton(self, event):
        #if self.curObj is None:
        #    return

        import datetime

        #if (self.tcSales.GetValue() == ""):
        #    return
                
        dlg = wx.TextEntryDialog(self, u'输入表名',
                                u'输入表名',self.dateStart.GetValue().Format('%Y%m%d'),wx.OK|wx.CANCEL|wx.CENTRE)
        if dlg.ShowModal() != wx.ID_OK:
            return
        name = dlg.GetValue()
        
        data = self.getData()
        data[CDataMallProfit.fi_id] = name
        
        obj = CDataMallProfit.factory()
        obj.setMulFieldVal(data)
        obj.insert()
        self.curObj = obj

        self.lc.refresh()

    def OnBtnDelButton(self, event):
        ''' 删除选中记录 '''
        if self.curObj is not None:
            self.curObj.delete()
            self.lc.refresh()
            
    def OnBtnModifyButton(self, event):
        ''' 保存修改 '''

        if self.curObj is None:
            return

        dlg = wx.MessageDialog(self, u'是否覆盖原记录？',u'提示',
                                    wx.YES_NO|wx.ICON_QUESTION)
        if(dlg.ShowModal() == wx.ID_NO):
            return

        self.curObj.setMulFieldVal(self.getData())
        self.curObj.update()

    def reclacYi(self):
        ''' 重算易天达利润 '''

        Sales = kit.toFloatOrZero(self.tcSalesYi.GetValue())
        Purchase = kit.toFloatOrZero(self.tcPurchaseYi.GetValue())
        Discount = kit.toFloatOrZero(self.tcDiscountYi.GetValue())
        Kickback = kit.toFloatOrZero(self.tcKickbackYi.GetValue())
        FillBackYi = kit.toFloatOrZero(self.tcFillBackYi.GetValue())

        NetProfitYi = Sales - Purchase - Discount - Kickback - FillBackYi
        self.tcNetProfitYi.SetValue('%.0f' %(NetProfitYi))

        self.reclacNetProfit()

    def reclacKickbackYi(self):
        ''' 重算易天达抽佣 '''
        
        sales = kit.toFloatOrZero(self.tcSalesYi.GetValue())
        self.tcKickbackYi.SetValue('%.0f' %(sales * CDataMallProfit.Yi_Kickback or 0))

    def OnTcSalesYiText(self, event):
        self.reclacKickbackYi()
        self.reclacYi()
        self.reclacExpense()
        self.RecalcPercentCostYi()

    def OnTcPurchaseYiText(self, event):
        self.reclacYi()
        self.RecalcPercentCostYi()

    def OnTcNetProfitYiText(self, event):
        self.RecalcGrossPercentYi()

    def OnTcDiscountYiText(self, event):
        self.reclacYi()

    def OnTcKickbackYiText(self, event):
        self.reclacYi()
        self.RecalcPercentFeeYi()

    def OnTcFillBackYiText(self, event):
        self.reclacYi()
        self.RecalcPercentFillYi()

    def reclacTong(self):
        ''' 重算同莱创利润 '''

        Sales = kit.toFloatOrZero(self.tcSalesTong.GetValue())
        Purchase = kit.toFloatOrZero(self.tcPurchaseTong.GetValue())
        Discount = 0 #kit.toFloatOrZero(self.tcDiscountTong.GetValue())
        Kickback = kit.toFloatOrZero(self.tcKickbackTong.GetValue())
        FillBack = kit.toFloatOrZero(self.tcFillBackTong.GetValue())

        NetProfit = Sales - Purchase - Discount - Kickback - FillBack
        self.tcNetProfitTong.SetValue('%.0f' %(NetProfit))

        self.reclacNetProfit()

    def reclacKickbackTong(self):
        ''' 重算易天达抽佣 '''
        
        sales = kit.toFloatOrZero(self.tcSalesTong.GetValue())
        self.tcKickbackTong.SetValue('%.0f' %(sales * CDataMallProfit.Tong_Kickback or 0))

    def OnTcNetProfitTongText(self, event):
        self.RecalcGrossPercentTong()

    def OnTcSalesTongText(self, event):
        self.reclacKickbackTong()
        self.reclacTong()
        self.reclacExpense()
        self.RecalcPercentCostTong()

    def OnTcPurchaseTongText(self, event):
        self.reclacTong()
        self.RecalcPercentCostTong()

    def OnTcDiscountTongText(self, event):
        self.reclacTong()

    def OnTcKickbackTongText(self, event):
        self.reclacTong()
        self.RecalcPercentFeeTong()

    def OnTcFillBackTongText(self, event):
        self.reclacTong()
        self.RecalcPercentFillTong()

    def reclacExpense(self):
        ''' 重算运营费用 '''
        
        sales = kit.str2Int(self.tcSalesTong.GetValue(), 0) + kit.str2Int(self.tcSalesYi.GetValue(), 0)
        self.tcExpensePercent.SetValue('%d'%(min(sales/50000,4)))
        self.tcExpense.SetValue('%.0f' %(min(sales/50000,4)*sales/100 or 0))

    def OnTcExpenseText(self, event):
        self.reclacNetProfit()
        
    def reclacNetProfit(self):
        '''重算净利润'''
        Yi = kit.toFloatOrZero(self.tcNetProfitYi.GetValue())
        Tong = kit.toFloatOrZero(self.tcNetProfitTong.GetValue())
        Expense = kit.toFloatOrZero(self.tcExpense.GetValue()) + kit.toFloatOrZero(self.tcMallExpense.GetValue())
        self.tcNetProfit.SetValue('%.0f' %(Yi+Tong-Expense or 0))

        self.RecalcNetPercent()


    def OnTcNetProfitText(self, event):
        pass

    def RecalcGrossPercentTong(self):
        '''重算 毛利率 同莱创'''
        
        grossProfit = kit.toFloatOrZero(self.tcNetProfitTong.GetValue())
        #cost = kit.toFloatOrZero(self.tcCost.GetValue())
        sales = kit.toFloatOrZero(self.tcSalesTong.GetValue())
        if (sales > 0):
            self.stPercentNetProfitTong.SetLabel('%.1f%%' %(grossProfit*100/sales))

    def RecalcGrossPercentYi(self):
        '''重算 毛利率 易天达'''
        
        grossProfit = kit.toFloatOrZero(self.tcNetProfitYi.GetValue())
        #cost = kit.toFloatOrZero(self.tcCost.GetValue())
        sales = kit.toFloatOrZero(self.tcSalesYi.GetValue())
        if (sales > 0):
            self.stPercentNetProfitYi.SetLabel('%.1f%%' %(grossProfit*100/sales))

    def RecalcNetPercent(self):
        '''重算 净利率'''
        
        NetProfit = kit.toFloatOrZero(self.tcNetProfit.GetValue())
        #cost = kit.toFloatOrZero(self.tcCost.GetValue())
        sales = kit.toFloatOrZero(self.tcSalesTong.GetValue()) + kit.toFloatOrZero(self.tcSalesYi.GetValue())
        if (sales > 0):
            self.stPercentNetProfit.SetLabel('%.1f%%' %(NetProfit*100/sales))

    def OnTcMallExpenseText(self, event):
        self.reclacNetProfit()

    def RecalcPercentCostYi(self):
        '''重算 成本率'''
        
        cost = kit.toFloatOrZero(self.tcPurchaseYi.GetValue())
        sales = kit.toFloatOrZero(self.tcSalesYi.GetValue())
        if (sales > 0 and cost>0):
            self.stPercentCostYi.SetLabel('%.1f%%' %(cost*100/sales))

    def RecalcPercentCostTong(self):
        '''重算 成本率'''
        
        cost = kit.toFloatOrZero(self.tcPurchaseTong.GetValue())
        sales = kit.toFloatOrZero(self.tcSalesTong.GetValue())
        if (sales > 0 and cost>0):
            self.stPercentCostTong.SetLabel('%.1f%%' %(cost*100/sales))

    def RecalcPercentFeeYi(self):
        '''重算 抽佣费率'''
        
        cost = kit.toFloatOrZero(self.tcKickbackYi.GetValue())
        sales = kit.toFloatOrZero(self.tcSalesYi.GetValue())
        if (sales > 0 and cost>0):
            self.stPercentFeeYi.SetLabel('%.1f%%' %(cost*100/sales))

    def RecalcPercentFeeTong(self):
        '''重算 抽佣费率'''
        
        cost = kit.toFloatOrZero(self.tcKickbackTong.GetValue())
        sales = kit.toFloatOrZero(self.tcSalesTong.GetValue())
        if (sales > 0 and cost>0):
            self.stPercentFeeTong.SetLabel('%.1f%%' %(cost*100/sales))

    def RecalcPercentFillYi(self):
        '''重算 回填费率'''
        
        cost = kit.toFloatOrZero(self.tcFillBackYi.GetValue())
        sales = kit.toFloatOrZero(self.tcSalesYi.GetValue())
        if (sales > 0 and cost>0):
            self.stPercentFillYi.SetLabel('%.1f%%' %(cost*100/sales))

    def RecalcPercentFillTong(self):
        '''重算 回填费率'''
        
        cost = kit.toFloatOrZero(self.tcFillBackTong.GetValue())
        sales = kit.toFloatOrZero(self.tcSalesTong.GetValue())
        if (sales > 0 and cost>0):
            self.stPercentFillTong.SetLabel('%.1f%%' %(cost*100/sales))
